<template>
  <div class="app-container">
    <el-card shadow="always">
      <div class="title">
        <span />
        <p>查询条件</p>
      </div>

      <el-form :model="seachForm" label-width="120px">
        <el-row :gutter="12">
          <el-col :span="12">
            <el-form-item label="对话id：">
              <el-input
                v-model="seachForm.sessionId"
                placeholder="请输入对话id"
              />
            </el-form-item>
          </el-col>

          <el-col :span="24" style="text-align: right">
            <el-button type="primary" @click="getInit(1)">查询</el-button>
            <el-button @click="rest">重置</el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-card>

    <el-card shadow="always" style="margin-top: 15px">
      <div class="title">
        <span />
        <p>对话列表</p>
      </div>

      <TableView
        :data-list="dataList"
        :loading="loading"
        :total="seachForm.total"
        :size="seachForm.size"
        :page="seachForm.page"
        @pagination="pagination"
      >
        <div slot="column">
          <el-table-column
            label="模型类型"
            align="center"
            prop="modelType"
            show-overflow-tooltip
          />

          <el-table-column
            label="对话id"
            align="center"
            prop="sessionId"
            show-overflow-tooltip
          />

          <el-table-column
            label="首次对话内容"
            align="center"
            prop="sessionId"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span>{{
                JSON.parse(scope.row.messages)[0].content[0].text || "---"
              }}</span>
            </template>
          </el-table-column>

          <el-table-column
            label="对话创建时间"
            align="center"
            prop="createTime"
            show-overflow-tooltip
          />

          <el-table-column
            label="对话字数"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span>{{ scope.row.messages.length }}字</span>
            </template>
          </el-table-column>

          <el-table-column
            label="操作"
            align="center"
            width="100"
            show-overflow-tooltip
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button type="text" @click="go_on(scope.row)"
                >继续对话</el-button
              >
            </template>
          </el-table-column>
        </div>
      </TableView>
    </el-card>
  </div>
</template>

<script>
import { deleteFile, doneFile, getUploadedFiles } from "@/api/chuizi";
import { getAllHistory } from "@/api/openAi";
import TableView from "@/components/TableView/index.vue";
export default {
  components: {
    TableView,
  },
  data() {
    return {
      dataList: [],
      loading: false,
      seachForm: {
        page: 1,
        size: 10,
        total: 0,
      },
    };
  },

  mounted() {
    this.getInit();
  },

  methods: {
    async getInit(page) {
      this.seachForm.page = page || this.seachForm.page;
      this.loading = true;
      const res = await getAllHistory(this.seachForm);
      if (res.code == 20000) {
        this.dataList = res.data || [];
        this.seachForm.total = res.total;
      } else {
        this.$message.error(res.msg);
      }
      this.loading = false;
    },

    rest() {
      this.seachForm = {};
      this.getInit();
    },

    // 继续对话
    go_on(item) {
      this.$router.push(`/ai_smart_smart/AI_help?sessionId=${item.sessionId}`);
    },

    pagination(e) {
      this.seachForm = e;
      this.getInit();
    },

    // 选择表格
    selectionChange(e) {
      this.selectTable = e;
    },
  },
};
</script>

<style></style>
